package com.sample.systemui.view;

import android.graphics.PixelFormat;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;

import com.sample.systemui.R;
import com.sample.servicefragment.SlidingDrawer;

/**
 * Sample6:step1
 * 请继承 SlidingDrawer 来定义自己支持滑动的 Panel 类。
 */
public class Panel extends SlidingDrawer {
    private static final String TAG = "Panel";

    /**
     * Sample6:step2
     * 实现 onCreateView() 方法，根据 layout 布局文件，生成自己的根 view 。
     */
    @Override
    public View onCreateView(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.sliding_drawer, null, false);

        /**
         * sample8:收起下拉panel
         */
        view.findViewById(R.id.button_push).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(v.getId() == R.id.button_push) {
                    Panel.this.close();

                }
            }
        });

        return view;
    }

    /**
     * Sample6:step3
     * 实现 createLayoutParams() 方法，创建 addView 所需的 LayoutParams 对象。
     */
    @Override
    public WindowManager.LayoutParams createLayoutParams() {

        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
                /* width */
                WindowManager.LayoutParams.MATCH_PARENT,
                /* height */
                (int)getContext().getResources().getDimension(R.dimen.panel_window_height),
                /* type */
                WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
                /* flag */
                /**
                 * sample7:允许软键盘弹出
                 * 不要设置如下flag：FLAG_ALT_FOCUSABLE_IM/FLAG_NOT_FOCUSABLE/FLAG_LOCAL_FOCUS_MODE
                 */
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                        | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
                /* format */
                PixelFormat.RGBA_8888
        );
        layoutParams.gravity =  Gravity.TOP;
        layoutParams.setTitle("Panel");
        layoutParams.packageName = getContext().getPackageName();
        return layoutParams;
    }

}
